<?php if( ! defined('BASEPATH')) exit('No direct script access allowed');
	/* ************************************************** *\
 * @company		: NovaITech							  *	
 * @author		: van.vo@novaitech.com				  * 
 * @copyright	: 2012								  * 
 * ================================================== *
 * @date		: 2/25/2012
 * @project		: CodeGenerator
 * @description	:
 *		- ENTRY POINT apps
 *
\* ************************************************** */

class codegenerator extends MY_Controller
{
	function __construct( ){
		parent::__construct( );
	}
	
    /* ------------------------------------------------------------ *\
     | - FUNC Purpose	: Entry point
     | - Parameters		: 
     |		Name			Type		Description
     |		---------------------------------------------------
     |		N/A
     |								
     | - Return			: 
     |			- N/A 
    \* ------------------------------------------------------------ */
	function index( )
	{
        // Data push to VIEW.
        // -------------------------------------------
        $data = array( );

        
        // Load list databases
        // --------------------------------------------------
        $data[ 'listdb' ] = $this->codegenerator_model->get_List_Database( );
        
        
        // Load WITH POSTBACK data
        // -------------------------------------------
        if( $_POST ){
            $databases = $data[ 'listdb' ];

            // First
            // POSTBACK database selected
            if( $this->input->post( 'db_data' ) ){
                // Send database to view
                $data[ 'dbname_selected'      ] =   $databases[ $this->input->post( 'databases' ) ];
                $data[ 'dbname_selectedIndex' ] =   $this->input->post( 'databases' );
                
                // Set selected index dropdown table = 0
                if( isset( $data[ 'records'   ] ))
                    unset( $data[ 'records'   ] );    
            } 

            // Last
            // POSTBACK table selected
            if( $this->input->post( 'table_data' ) ){
                
                // Resend database infor to view
                if( !isset( $data[ 'dbname_selected' ] ) ){
                    $data[ 'dbname_selected'      ] =   $databases[ $this->input->post( 'databases' ) ];
                    $data[ 'dbname_selectedIndex' ] =   $this->input->post( 'databases' );
                }
                
                // Send table infor to view
                $tables = $this->codegenerator_model->get_List_Tables( $databases[ $this->input->post( 'databases' ) ] );
                $data[ 'tablename_selected'      ]  =   $tables[ $this->input->post( 'tables' ) ];
                $data[ 'tablename_selectedIndex' ]  =   $this->input->post( 'tables' );
                $data[ 'records'                 ]  =   $this->codegenerator_model->get_Detail_Fields( $data[ 'tablename_selected' ] );
             }    
                            
        }
        // Load view with data  
        // -------------------------------------------      
        $this->load->view( 'codegenerator', $data );
	}
}
?>